//
//  fourthViewController.m
//  豆瓣综合网页
//
//  Created by dllo on 15/12/31.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "fourthViewController.h"
#import "fourthTableViewCell.h"
#import "fourth2ViewController.h"
#import "fourth1ViewController.h"
#import "activityfourthViewController.h"
#import "ZLFDateBaseHandle.h"
#import "activityModel.h"
@interface fourthViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain) UITableView *tableView;
@property (nonatomic, retain) NSMutableArray *arr;
@end

@implementation fourthViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.tableView = [[UITableView alloc] init];
    self.tableView.backgroundColor = [UIColor whiteColor];
    _tableView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
    [self.view addSubview:_tableView];
    [_tableView release];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"登录" style:UIBarButtonItemStylePlain target:self action:@selector(itemAction:)];
    self.navigationItem.rightBarButtonItem = item;
    [self.tableView registerClass:[fourthTableViewCell class] forCellReuseIdentifier:@"cell"];
}



- (void)itemaction1:(UIBarButtonItem *)item {
//    UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithTitle:@"登录" style:UIBarButtonItemStylePlain target:self action:@selector(itemAction:)];
//    self.navigationItem.rightBarButtonItem = item1;

    
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"确认是否注销" preferredStyle:(UIAlertControllerStyleAlert)];

    UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

        UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"登录" style:UIBarButtonItemStylePlain target:self action:@selector(itemAction:)];
        self.navigationItem.rightBarButtonItem = item;
    }];
    UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    [alert addAction:action1];
    [alert addAction:action2];
    [self presentViewController:alert animated:YES completion:nil];

    
}

- (void)itemAction:(UIBarButtonItem *)item {
    fourth1ViewController *fourth1 = [[fourth1ViewController alloc] init];
    UINavigationController *fouth1Nav = [[UINavigationController alloc] initWithRootViewController:fourth1];
        [self presentViewController:fouth1Nav animated:YES completion:^{
        }];
    fourth1.block = ^(NSString *str) {
        UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:str style:(UIBarButtonItemStylePlain) target:self action:@selector(itemaction1:)];
        self.navigationItem.rightBarButtonItem = item;
    };
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 3;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    fourthTableViewCell *cell  = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (indexPath.row == 0) {
        cell.textLabel.text = @"我的活动";
    }
    if (indexPath.row == 1) {
        cell.textLabel.text = @"我的电影";
    }
    if (indexPath.row == 2) {
        cell.textLabel.text = @"清除缓存";
    }
    return cell;
}

-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 2) {
        UIAlertController *aler = [UIAlertController alertControllerWithTitle:@"提示" message:@"是否清除缓存" preferredStyle:(UIAlertControllerStyleAlert)];
        UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault
 handler:^(UIAlertAction * _Nonnull action) {

     
     [[ZLFDateBaseHandle shareActivity] actdeleteTabel:nil];
     
 }];
        UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        
        [aler addAction:action];
        [aler addAction:action1];
        [self presentViewController:aler animated:YES completion:nil];
    }else{
    activityfourthViewController *activityVC = [[activityfourthViewController alloc] init];
    activityVC.indexpath = indexPath;
    [self.navigationController pushViewController:activityVC animated:YES];
    }
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
